# match-case
command = "start"
match command:
    case "start":
        print("Starting the car...")
    case "stop":
        print("Stopping the car...")
    case "quit":
        print("Quitting the program...")
    case _:
        print("Invalid command.")

# match-case中使用守卫条件
number = 42
match number:
    case x if x > 0:
        print(f"{number} 是正数")
    case x if x < 0:
        print(f"{number} 是负数")
    case _:
        print(f"{number} 是零")

# match-case匹配序列
point = (1, 2)
match point:
    case (0, 0):
        print("原点")
    case (0, y):
        print(f"y轴上的点，y={y}")
    case (x, 0):
        print(f"x轴上的点，x={x}")
    case (x, y):
        print(f"其他点，x={x}, y={y}")
    case _:
        print("无效的点")

# match-case匹配字典
person = {"name": "张三", "age": 18}
match person:
    case {"name": name, "age": age}:
        print(f"姓名：{name}，年龄：{age}")
    case _:
        print("无效的person")